/*

BlackRabbit - OpenSource IDE.
@author Edward Sarkisyan (edward.sarkisyan@gmail.com)
Use LGPL (http://www.gnu.org/copyleft/lesser.html)

*/

#include "extentionmanager.h"
#include "ui_extentionmanager.h"

ExtentionManager::ExtentionManager(QWidget *parent, QVector<Language*> *extentions ) :
    QDialog(parent),
    m_ui(new Ui::ExtentionManager)
{
    m_ui->setupUi(this);
    for(QVector<Language*>::Iterator i = extentions->begin();
        i != extentions->end();
        i++)
    {
        qDebug("i");
        try
        {
            m_extentions.insert((*i)->name(), *i);
        }
        catch(...)
        {
            qDebug("Error in loading extention");
        }
    }
}

ExtentionManager::~ExtentionManager()
{
    m_extentions.clear();
    delete m_ui;
}

void ExtentionManager::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

Language* ExtentionManager::findExtention(QString key)
{
    qDebug(key.toStdString().c_str());
    QMap<QString, Language*>::iterator i = m_extentions.find(key);
    qDebug("bastards");
    if(i == m_extentions.end())
        return 0;
    qDebug("bastards");
    return i.value();
}
